package appx.craft.droid.uc;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import appx.craft.droid.R;

public class AppBottomBar extends LinearLayout implements OnClickListener {

	private final String TAG = AppBottomBar.class.getCanonicalName();
	
	private TabMenuClickListener mClickCallBack;
	private Context mContext;
	private Button btn_top_feeds,btn_serach,btn_camera;
	
	public AppBottomBar(Context context) {
		super(context);
		mContext = context;
		mClickCallBack = (TabMenuClickListener)context;
		initalization();
	}

	public AppBottomBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		mContext = context;
		mClickCallBack = (TabMenuClickListener)context;
		initalization();
	}
	
	public AppBottomBar(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		mContext = context;
		mClickCallBack = (TabMenuClickListener)context;
		initalization();
	}

	
	public void initalization() {
		View mView = LayoutInflater.from(mContext).inflate(
				R.layout.app_bottom_bar, this, true);
		btn_top_feeds = (Button)mView.findViewById(R.id.btn_top_feeds);
		btn_top_feeds.setOnClickListener(this);
		btn_camera =(Button)mView.findViewById(R.id.btn_camera);
		btn_camera.setOnClickListener(this);
		btn_serach = (Button)mView.findViewById(R.id.btn_serach);
		btn_serach.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		
		if(v.getId() == R.id.btn_top_feeds){
			setMenuTabActivate(R.id.btn_top_feeds);
			mClickCallBack.onMenuItemClick(R.id.btn_top_feeds);
		}else if(v.getId() == R.id.btn_camera){
			setMenuTabActivate(R.id.btn_camera);
			mClickCallBack.onMenuItemClick(R.id.btn_camera);
		}else if(v.getId() == R.id.btn_serach){
			setMenuTabActivate(R.id.btn_serach);
			mClickCallBack.onMenuItemClick(R.id.btn_serach);
		}
		
	}
	
	private void setMenuTabActivate(int getID){
		
		if(getID == R.id.btn_top_feeds){
			
			btn_top_feeds.setBackgroundDrawable(getResources().getDrawable(R.drawable.icon_btn_star_pressed));
			btn_serach.setBackgroundDrawable(getResources().getDrawable(R.drawable.icon_btn_search_default));
			
		}else if(getID == R.id.btn_camera){
			btn_top_feeds.setBackgroundDrawable(getResources().getDrawable(R.drawable.icon_btn_star_normal));
			btn_serach.setBackgroundDrawable(getResources().getDrawable(R.drawable.icon_btn_search_default));
			
		}else if(getID == R.id.btn_serach){
			
			btn_serach.setBackgroundDrawable(getResources().getDrawable(R.drawable.icon_btn_search_pressed));
			btn_top_feeds.setBackgroundDrawable(getResources().getDrawable(R.drawable.icon_btn_star_normal));
		}
	}

}
